import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiNewPage(Base):
    """
    语音训练新闻页

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的返回键
        self.new_back_btn = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format('ivBack'))

        # 左侧的home键
        self.new_home_btn = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format('ivHome'))

        # 新闻标题
        self.new_title_text = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("tv_net"))

        # 新闻标签
        self.new_tab_btn = (By.XPATH, Yomi.new_tab_btn.format(""))

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.new_back_btn)

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.new_home_btn)

    def get_title(self):
        """
        获取新闻标题

        :return:获取元素
        """
        return self.find_element_o(self.new_title_text)

    def get_tab(self, index=1):
        """
        获取新闻tab名称

        :return:获取元素
        """
        self.new_tab_btn = (By.XPATH, Yomi.new_tab_btn.format(index))
        return self.find_element_o(self.new_tab_btn)

    def click_tab(self, index=1):
        """
        点击新闻tab名称

        :return:获取元素
        """
        self.new_tab_btn = (By.XPATH, Yomi.new_tab_btn.format(index))
        self.click_element(self.new_tab_btn)

    def is_display_yomi_new(self):
        """
        查看是否新闻页

        :return:
        """
        return self.is_display(self.new_title_text)
